package com.example.demo.controller.admin;
import com.example.demo.dao.Indent;
import com.example.demo.dao.SearchIndentResponse;
import com.example.demo.service.indentService;
import com.example.demo.util.Msg;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/indent")
public class indentController {
    @Autowired
    private indentService indentService;
    @GetMapping
    public String indentPage(){
        return "indent-list";
    }
    //未发货订单的地址信息
    @GetMapping("/search")
    @ResponseBody
    public SearchIndentResponse searchIndentResponse(@RequestParam ("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        return  indentService.searchIndent(pageNum,pageSize);
    }
    //未发货订单的商品信息
//    @GetMapping("/searchgoods")
//    @ResponseBody
//    public SearchIndentResponse searchGoodsResponse(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize") Integer pageSize){
//        return indentService.findgoods(pageNum,pageSize);
//    }
//    //未收货订单的商品信息
//    @GetMapping("/searchgoods1")
//    @ResponseBody
//    public SearchIndentResponse searchGoodsResponse1(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize") Integer pageSize){
//        return indentService.findgoods1(pageNum,pageSize);
//    }
    @GetMapping("/show")
    public String show(){
        return "indent-list2";
    }
    @GetMapping("/search1")
    @ResponseBody
    public SearchIndentResponse searchIndentResponse1(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize){
        return indentService.searchIndent1(pageNum,pageSize);
    }
    //得到所有订单
    @RequestMapping(value = "/all" ,method = RequestMethod.GET)
    public String  getIndentPage(Model model){
        List<Indent>indents=indentService.findAll();
        model.addAttribute("msg","1");
        model.addAttribute("indents",indents);
        return "order";
    }
    @RequestMapping("/toOrder")
    public String toOrder(){
        return "order";
    }

    @RequestMapping(value="/noPay",method = RequestMethod.GET)
    public String getIndentPage1(Model model){
        List<Indent>indent=indentService.findNoPay();
        model.addAttribute("msg","2");
        model.addAttribute("indent",indent);
        return  "order";
    }

    @GetMapping("/noSend")
    public String getIndentPage2(Model model){
        List<Indent>indentd=indentService.findNoSend();
        model.addAttribute("msg","3");
        model.addAttribute("indentd",indentd);
        return  "order";
    }
    @GetMapping("/noReceive")
    public String getIndentPage3(Model model){
        List<Indent>indente=indentService.findNoReceive();
        model.addAttribute("msg","4");
        model.addAttribute("indente",indente);
        return  "order";
    }
    @GetMapping("/noComplete")
    public String getIndentPage4(Model model){
        List<Indent>indentc=indentService.findNoComplete();
        model.addAttribute("msg","5");
        model.addAttribute("indentc",indentc);
        return  "order";
    }
    @GetMapping("/show1")
    public String show1(){return "indent-list3";}

    @GetMapping("/search2")
    @ResponseBody
    public SearchIndentResponse searchIndentResponse2(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize){
        return indentService.searchIndent2(pageNum,pageSize);
    }
    //    //删除单个订单
//    @DeleteMapping("/delete")
//    public boolean  deleteIndent(@RequestParam("id") Integer id){
//        int deletedata = indentService.delectIndent(id);
//            return deletedata>0;
//
//    }
    //修改发货信息
    @RequestMapping("/delivery")
    public String  updateIssend(@RequestParam("id") Integer id){
        int updatedata = indentService.uodateIssent(id);
        if(updatedata>0)
            return "indent-list";
        return "redirect: 404";
    }
    //测试
//    @GetMapping("/search")
//    @ResponseBody
//    public Msg searchIndentResponse(@RequestParam("pageNum")Integer pageNum,
//                                   @RequestParam("pageSize")Integer pageSize){
//        PageHelper.startPage(pageNum,pageSize);
//        List<Indent> indents= indentService.findIsendIndent();
//        Msg msg = new Msg();
//        return msg.addIndent(((Page)indents).getTotal(),indents);
//    }



}
